﻿using System;
using System.Collections.Generic;
using System.Linq;
using ExpenseSystem.Common;
using ExpenseSystem.Fether;
using ExpenseSystem.Lor;
using ExpenseSystem.Model;

namespace ExpenseSystem.Fether
{
    public class EmployeeFetcher:NormalFetcher<EmployeeModel>
    {
        public EmployeeModel GetEmployeeByUser( long site, long userId, out string message)
        {
            IList<EmployeeModel> result = List( site, OrderBy.GetDefault(), Limit.GetDefault(), out message, out rows, Restrain.Eq("UserProjection", userId));
            if (result.Count > 0)
                return result.First();
            return null;
        }
        public EmployeeModel GetEmployeeByCode( long site, string code, out string message)
        {
            IList<EmployeeModel> result = List( site, OrderBy.GetDefault(), Limit.GetDefault(), out message,out rows, Restrain.Eq("Code", code));
            if (result.Count > 0)
                return result.First();
            return null;
        }
        public IList<EmployeeModel> ListEmployeeByUser(long user, out int rows)
        {
            string message;
            IList<EmployeeModel> result = SqlProvider.GetDbInstance<EmployeeModel>().Select(tran, OrderBy.GetDefault(), Limit.GetDefault(), out message,out rows, Restrain.Eq("UserProjection",user));
            return result;
        }
        public IList<EmployeeModel> ListEmployeeByTitle(long site,long title, out string message, out int rows)
        {
            IList<EmployeeModel> result = SqlProvider.GetDbInstance<EmployeeModel>().Select(tran, OrderBy.GetDefault(), Limit.GetDefault(), out message,out rows, Restrain.Eq("TitleId", title));
            return result;
        }
        public IList<EmployeeModel> ListEmployeeByDepartment(long site, long dep, out string message,out int rows)
        {
            IList<EmployeeModel> result = SqlProvider.GetDbInstance<EmployeeModel>().Select(tran, OrderBy.GetDefault(), Limit.GetDefault(), out message,out rows, Restrain.Eq("DepartmentId", dep));
            return result;
        }
    }
}
